<?php

if (isset($_POST['submitted'])) {

	require_once ('koneksiDB.php'); // Connect to the db.
		
	$errors = array(); // Inisialisasi array error
	
	// Cek nama pertama
	if (empty($_POST['nama'])) {
		$errors[] = 'Kolom nama harus terisi';
	} else {
		$nama = mysqli_real_escape_string($conn, trim($_POST['nama']));
	}
	
	// Cek alamat email
	if (empty($_POST['email'])) {
		$errors[] = 'alamat email harus terisi.';
	} else {
		$email = mysqli_real_escape_string($conn, trim($_POST['email']));
	}
	
	if (empty($_POST['subject'])) {
		$errors[] = 'subject harus terisi.';
	} else {
		$subject = mysqli_real_escape_string($conn, trim($_POST['subject']));
	}
	
	// Check for a password and match against the confirmed password:
	if (empty($_POST['isi'])) {
		$errors[] = 'Masukkan komentar dan saran anda untuk kami.';
	} else {
		$isi = mysqli_real_escape_string($conn, trim($_POST['isi']));
	}
	
	if (empty($errors)) { // Jika semuanya sudah OK.
	
		// Register user ke conn...
		
		// Make the query:
		$date = date('Y-m-d H:i:s');
		$query = "INSERT INTO contact (nama, email, subject, isi, regristration_date) VALUES ('$nama','$email', '$subject', '$isi','$date')";		
		$run = @mysqli_query ($conn, $query); // jalankan query.
		
		// Include footer dan hentikan skrip:
		//include ('includes/footer.html'); 
		
		
	} else { // Tmapilkan error.
	
		/*echo '<h1>Error!</h1>
		<p class="error">Error-nya :<br />';
		foreach ($errors as $msg) { // Cetak error.
			echo " - $msg<br />\n";
		}
		echo '</p><p>Silahkan coba lagi.</p><p><br /></p>';
		*/
	} // End dari if (empty($errors)) IF.
	
	mysqli_close($conn); // Tutup koneksi conn.
	header("Location: index.php");
} // End dari the main Submit conditional.

?>
